package com.sangeng.utils;

import org.springframework.beans.BeanUtils;

import java.util.List;

public class BeanUtil {

    private BeanUtil(){}
    public static <T> T copyBean(Object source,Class<T> clazz){
        T target = null;
        try {
            target = clazz.newInstance();
            BeanUtils.copyProperties(source,target);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return target;
    }

    public static <T> List<T> copyBeanList(List<?> source, Class<T> clazz){
        return source.stream()
                .map(s -> copyBean(s, clazz))
                .toList();
    }

}
